package com.sls.sys.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.page.Pagination;
import com.sls.sys.dao.RolePermissionDAo;
import com.sls.sys.pojo.PermissionInfoVO;
import com.sls.sys.pojo.RolePermission;

@Repository("rolePermissionDAO")
public class RolePermissionDAOImpl extends SuperDAO<RolePermission> implements
		RolePermissionDAo {

	@Override
	public Pagination<RolePermission> fiandPage(RolePermission rp) {
		Pagination<RolePermission> list = super.queryPagination(
				"mybatis.xml.RolePermission.findRolePermissionPage",
				"mybatis.xml.RolePermission.findRolePermissionNumber", rp);
		for (RolePermission role : list.getList()) {
			role.setPermissions(findPermissionByRoleId(role.getRoleId()));
		}
		return list;
	}

	@Override
	public List<PermissionInfoVO> findPermissionByRoleId(String roleId) {
		List<PermissionInfoVO> list = getSqlSession().selectList(
				"mybatis.xml.PermissionInfoMapper.findByroleId", roleId);
		return list;
	}

	@Override
	public void deleteRolePermission(String roleId) {
		getSqlSession().delete(
				"mybatis.xml.RolePermission.deleteRolePermission", roleId);
	}

	@Override
	public void insertRolePermission(RolePermission rp) {
		getSqlSession().insert("mybatis.xml.RolePermission.insert", rp);
	}

}
